




/*
'===============================================================================
'  HNG.Portal.BL.TblCommentManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class TblCommentManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_Id="Id";
				
				public const String Field_Idtintuc="Idtintuc";
				
				public const String Field_TenNguoiViet="TenNguoiViet";
				
				public const String Field_Email="Email";
				
				public const String Field_NoiDung="NoiDung";
				
				public const String Field_DanhDau="DanhDau";
				
				public const String Field_Active="Active";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblCommentManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_Id,typeof(int));
			
						
			
			dt.Columns.Add(Field_Idtintuc,typeof(int));
			
						
			
			dt.Columns.Add(Field_TenNguoiViet,typeof(string));
			
						
			
			dt.Columns.Add(Field_Email,typeof(string));
			
						
			
			dt.Columns.Add(Field_NoiDung,typeof(string));
			
						
			
			dt.Columns.Add(Field_DanhDau,typeof(bool));
			
						
			
			dt.Columns.Add(Field_Active,typeof(bool));
			
			            
            return dt;			
		}
			
		public TblCommentEntity Convert_Entity(TblCommentEntity _TblCommentEntity,TblCommentEntity _TblCommentEntity_XML)
		{	
			
				
			_TblCommentEntity.Id= _TblCommentEntity_XML.Id;
				
			_TblCommentEntity.Idtintuc= _TblCommentEntity_XML.Idtintuc;
				
			_TblCommentEntity.TenNguoiViet= _TblCommentEntity_XML.TenNguoiViet;
				
			_TblCommentEntity.Email= _TblCommentEntity_XML.Email;
				
			_TblCommentEntity.NoiDung= _TblCommentEntity_XML.NoiDung;
				
			_TblCommentEntity.DanhDau= _TblCommentEntity_XML.DanhDau;
				
			_TblCommentEntity.Active= _TblCommentEntity_XML.Active;
				
			
			return _TblCommentEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public TblCommentEntity Insert(TblCommentEntity TblCommentEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(TblCommentEntity, true);
			}
			return TblCommentEntity;
		}

		
		public TblCommentEntity Insert(int Id, int Idtintuc, string TenNguoiViet, string Email, string NoiDung, bool DanhDau, bool Active)
		{
			TblCommentEntity _TblCommentEntity = new TblCommentEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblCommentEntity.Id = Id;
				_TblCommentEntity.Idtintuc = Idtintuc;
				_TblCommentEntity.TenNguoiViet = TenNguoiViet;
				_TblCommentEntity.Email = Email;
				_TblCommentEntity.NoiDung = NoiDung;
				_TblCommentEntity.DanhDau = DanhDau;
				_TblCommentEntity.Active = Active;
				adapter.SaveEntity(_TblCommentEntity, true);
			}
			return _TblCommentEntity;
		}

		public TblCommentEntity Insert(int Idtintuc, string TenNguoiViet, string Email, string NoiDung, bool DanhDau, bool Active)
		{
			TblCommentEntity _TblCommentEntity = new TblCommentEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblCommentEntity.Idtintuc = Idtintuc;
				_TblCommentEntity.TenNguoiViet = TenNguoiViet;
				_TblCommentEntity.Email = Email;
				_TblCommentEntity.NoiDung = NoiDung;
				_TblCommentEntity.DanhDau = DanhDau;
				_TblCommentEntity.Active = Active;
				adapter.SaveEntity(_TblCommentEntity, true);
			}
			return _TblCommentEntity;
		}

		public bool Update(TblCommentEntity _TblCommentEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(TblCommentFields.Id == _TblCommentEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_TblCommentEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(TblCommentEntity _TblCommentEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_TblCommentEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int Id, int Idtintuc, string TenNguoiViet, string Email, string NoiDung, bool DanhDau, bool Active)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblCommentEntity _TblCommentEntity = new TblCommentEntity(Id);
				if (adapter.FetchEntity(_TblCommentEntity))
				{
				
					_TblCommentEntity.Idtintuc = Idtintuc;
					_TblCommentEntity.TenNguoiViet = TenNguoiViet;
					_TblCommentEntity.Email = Email;
					_TblCommentEntity.NoiDung = NoiDung;
					_TblCommentEntity.DanhDau = DanhDau;
					_TblCommentEntity.Active = Active;
					adapter.SaveEntity(_TblCommentEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblCommentEntity _TblCommentEntity = new TblCommentEntity(Id);
				if (adapter.FetchEntity(_TblCommentEntity))
				{
					adapter.DeleteEntity(_TblCommentEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("TblCommentEntity", null);
			}
		}
		
		
		public int DeleteById(int Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblCommentEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByIdtintuc(int Idtintuc)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.Idtintuc == Idtintuc);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblCommentEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTenNguoiViet(string TenNguoiViet)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.TenNguoiViet == TenNguoiViet);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblCommentEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByEmail(string Email)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.Email == Email);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblCommentEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByNoiDung(string NoiDung)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.NoiDung == NoiDung);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblCommentEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByDanhDau(bool DanhDau)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.DanhDau == DanhDau);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblCommentEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByActive(bool Active)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.Active == Active);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblCommentEntity", filter);
			}
			return toReturn;
		}
		

		
		public TblCommentEntity SelectOne(int Id)
		{
			TblCommentEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblCommentEntity _TblCommentEntity = new TblCommentEntity(Id);
				if (adapter.FetchEntity(_TblCommentEntity))
				{
					toReturn = _TblCommentEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _TblCommentCollection = new EntityCollection( new TblCommentEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblCommentCollection, null, 0, null);
			}
			return _TblCommentCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblCommentCollection = new EntityCollection(new TblCommentEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblCommentCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectById(int Id)
		{
			EntityCollection _TblCommentCollection = new EntityCollection(new TblCommentEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblCommentCollection, filter, 0, null);
			}
			return _TblCommentCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(int Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblCommentCollection = new EntityCollection(new TblCommentEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblCommentCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByIdtintuc(int Idtintuc)
		{
			EntityCollection _TblCommentCollection = new EntityCollection(new TblCommentEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.Idtintuc == Idtintuc);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblCommentCollection, filter, 0, null);
			}
			return _TblCommentCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdtintucRDT(int Idtintuc)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblCommentCollection = new EntityCollection(new TblCommentEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.Idtintuc == Idtintuc);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblCommentCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTenNguoiViet(string TenNguoiViet)
		{
			EntityCollection _TblCommentCollection = new EntityCollection(new TblCommentEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.TenNguoiViet == TenNguoiViet);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblCommentCollection, filter, 0, null);
			}
			return _TblCommentCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTenNguoiVietRDT(string TenNguoiViet)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblCommentCollection = new EntityCollection(new TblCommentEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.TenNguoiViet == TenNguoiViet);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblCommentCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByEmail(string Email)
		{
			EntityCollection _TblCommentCollection = new EntityCollection(new TblCommentEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.Email == Email);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblCommentCollection, filter, 0, null);
			}
			return _TblCommentCollection;
		}
		
		// Return DataTable
		public DataTable SelectByEmailRDT(string Email)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblCommentCollection = new EntityCollection(new TblCommentEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.Email == Email);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblCommentCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByNoiDung(string NoiDung)
		{
			EntityCollection _TblCommentCollection = new EntityCollection(new TblCommentEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.NoiDung == NoiDung);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblCommentCollection, filter, 0, null);
			}
			return _TblCommentCollection;
		}
		
		// Return DataTable
		public DataTable SelectByNoiDungRDT(string NoiDung)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblCommentCollection = new EntityCollection(new TblCommentEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.NoiDung == NoiDung);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblCommentCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByDanhDau(bool DanhDau)
		{
			EntityCollection _TblCommentCollection = new EntityCollection(new TblCommentEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.DanhDau == DanhDau);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblCommentCollection, filter, 0, null);
			}
			return _TblCommentCollection;
		}
		
		// Return DataTable
		public DataTable SelectByDanhDauRDT(bool DanhDau)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblCommentCollection = new EntityCollection(new TblCommentEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.DanhDau == DanhDau);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblCommentCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByActive(bool Active)
		{
			EntityCollection _TblCommentCollection = new EntityCollection(new TblCommentEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.Active == Active);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblCommentCollection, filter, 0, null);
			}
			return _TblCommentCollection;
		}
		
		// Return DataTable
		public DataTable SelectByActiveRDT(bool Active)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblCommentCollection = new EntityCollection(new TblCommentEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblCommentFields.Active == Active);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblCommentCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
